<template>
  <div class="body">
    <div style="width: 100%; height: 100px">
      <a-form formLayout="horizontal" :label-col="{ span: 5 }" :wrapper-col="{ span: 18 }">
        <a-row :gutter="[16, 8]">
          <a-col :span="6">
            <span>开始时间区间：</span>
            <a-range-picker
              style="width: 280px"
              v-model="queryParam.startTimeRange"
              @change="onDateRangeChange($event, 'StartTime')"
              :ranges="dataRange"
            />
            <!-- <a-space>
              <a-button icon="left" @click.stop="goPrev" />
              <a-date-picker
                style="width: 130px"
                v-model:value="currentMonth"
                placeholder="选择日期"
                :allowClear="false"
                @change="onChangeDate"
              />
              <a-button icon="right" @click.stop="goNext" />
            </a-space> -->
          </a-col>
          <a-col :span="6">
            <span>结束时间区间：</span>
            <a-range-picker
              style="width: 280px"
              v-model="queryParam.endTimeRange"
              @change="onDateRangeChange($event, 'EndTime')"
              :ranges="dataRange"
            />
          </a-col>
          <a-col :span="4"> </a-col>
          <!--        <a-col :span="4">-->
          <!--          <span>时间：</span>-->
          <!--          <a-date-picker v-model="time" style="width: 180px"/>-->
          <!--        </a-col>-->
          <a-col :span="4">
            <!--          <span>品种：</span>-->
            <!--          <j-dict-select-tag placeholder="请选择品种" v-model="queryParam.productType" dictCode="crm_product_type_spun_yarn,product_type,id" style="width: 180px"/>-->
          </a-col>
          <a-col :span="4">
            <a-form-model-item label="车间" prop="workshop">
              <j-dict-select-tag
                placeholder="请选择车间"
                v-model="queryParam.workshop"
                dictCode="workshop"
                style="width: 180px"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form>
      <div>
        <a-space style="float: right;">
          <a-upload
            name="file"
            :showUploadList="false"
            :multiple="false"
            :headers="tokenHeader"
            :action="importExcelUrl"
            @change="handleImportExcel"
          >
            <a-button type="default" icon="import">导入</a-button>
          </a-upload>
          <a-button @click="handleExportXls('络筒品种公定参数')" type="default" icon="export">导出报表</a-button>
          <a-button @click="handleSearch()" type="primary">搜索</a-button>
          <a-button @click="handleAdd" type="primary">新增</a-button>
          <a-button @click="batchDel" type="default">批量删除</a-button>
        </a-space>
      </div>
    </div>
    <div style="margin-top: 20px;">
      <a-table
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :columns="columns"
        rowKey="id"
        :data-source="dataSource"
        :scroll="{ x: 2500 }"
        :pagination="ipagination"
      >
        <!-- 操作 -->
        <a-space slot="action" slot-scope="text, record">
          <template>
            <a-button style="padding: 0px" type="link" icon="edit" @click="handleEdit(record)">编辑</a-button>
            <a-popconfirm title="确认要删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button style="color: red; padding: 0px" type="link" icon="delete">删除</a-button>
            </a-popconfirm>
          </template>
        </a-space>
      </a-table>
    </div>
    <luo-tong-pin-zhong-gong-ding-can-shu-modal
      ref="modalForm"
      @ok="modalFormOk"
      :planTime="queryParam.planTime"
    ></luo-tong-pin-zhong-gong-ding-can-shu-modal>
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import LuoTongPinZhongGongDingCanShuModal from './modules/LuoTongPinZhongGongDingCanShuModal'
import { copyYesterdayDailyPlan, getGenerateSalary } from '../../../api/customApi'
import moment from 'moment'
const path = '/crm_product_type_params_spooling/crmProductTypeParamsSpooling'
export default {
  mixins: [JeecgListMixin],
  components: { LuoTongPinZhongGongDingCanShuModal },
  data() {
    return {
      currentMonth: moment(),
      columns,
      queryParam: {
        // planTime: moment().format('YYYY-MM-DD')
      },
      url: {
        list: path + '/list',
        delete: path + '/delete',
        deleteBatch: path + '/deleteBatch',
        importExcelUrl: path + '/importExcel',
        exportXlsUrl: '/crm_product_type_params_spooling/crmProductTypeParamsSpooling/exportExcel'
      },
      dataRange: {
        当天: [moment().startOf('day'), moment()],
        昨天: [
          moment()
            .startOf('day')
            .subtract(1, 'days'),
          moment()
            .startOf('day')
            .subtract(1, 'days')
        ],
        本周: [
          moment()
            .startOf('weeks')
            .subtract(0, 'weeks'),
          moment()
        ],
        上周: [
          moment()
            .startOf('week')
            .subtract(1, 'weeks'),
          moment()
            .endOf('week')
            .subtract(1, 'weeks')
        ],
        本月: [
          moment()
            .startOf('months')
            .subtract(0, 'months'),
          moment()
        ],
        上月: [
          moment()
            .month(moment().month() - 1)
            .startOf('month'),
          moment()
            .month(moment().month() - 1)
            .endOf('month')
        ],
        本季度: [
          moment()
            .quarter(moment().quarter())
            .startOf('quarter'),
          moment()
        ],
        本年度: [
          moment()
            .startOf('year')
            .subtract(0, 'years'),
          moment()
        ]
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`
    }
  },
  methods: {
    goPrev() {
      var newMonth = moment(this.currentMonth).subtract(1, 'day')
      this.currentMonth = newMonth
      this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
      this.searchQuery()
    },
    goNext() {
      var newMonth = moment(this.currentMonth).add(1, 'day')
      this.currentMonth = newMonth
      this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
      this.searchQuery()
    },
    onChangeDate(date, dateString) {
      this.queryParam.planTime = dateString
      this.searchQuery()
    },
    changeObject() {},
    refresh() {
      this.searchQuery()
    },
    handleSearch() {
      this.searchQuery()
      this.visible = false
    },
    handleCancel() {
      this.visible = false
    },
    handleReset() {
      this.searchReset()
    },
    add() {
      this.visable1 = true
    },
    detail(record) {},
    onChangePage(e) {
      this.ipagination.current = e
      this.loadData()
    },
    generateSalary() {
      let query = {
        // planTime:this.currentMonth
        // planTime: this.queryParam.planTime
      }
      getGenerateSalary(query).then(res => {
        if (res.success) {
          this.$message.success('生成成功')
          this.searchQuery()
        }
      })
    },
    onDateRangeChange(event, extraParam) {
      this.$set(this.queryParam, 'start' + extraParam, moment(event[0]).format('YYYY-MM-DD 00:00:00'))
      this.$set(this.queryParam, 'end' + extraParam, moment(event[1]).format('YYYY-MM-DD 23:59:59'))
    }
  }
}

const columns = [
  { align: 'center', title: '创建日期', width: 200, dataIndex: 'createTime', key: 'createTime', fixed: 'left' },
  { align: 'center', title: '公司', width: 220, dataIndex: 'company_dictText', key: 'company_dictText', fixed: 'left' },
  {
    align: 'center',
    title: '车间',
    width: 100,
    dataIndex: 'workshop_dictText',
    key: 'workshop_dictText',
    fixed: 'left'
  },
  {
    align: 'center',
    title: '工序',
    width: 100,
    dataIndex: 'workingProcedure_dictText',
    key: 'workingProcedure_dictText',
    fixed: 'left'
  },
  { align: 'center', title: '开始时间', width: 180, dataIndex: 'startTime', key: 'startTime' },
  { align: 'center', title: '结束时间', width: 180, dataIndex: 'endTime', key: 'endTime' },
  { align: 'center', title: '车号', dataIndex: 'deviceNo', key: 'deviceNo', width: 150 },
  { align: 'center', title: '机型', dataIndex: 'deviceModel', key: 'deviceModel', width: 150 },
  { align: 'center', title: '品种类型', width: 150, dataIndex: 'productCategory', key: 'productCategory' },
  { align: 'center', title: '品种', dataIndex: 'productType_dictText', key: 'productType_dictText', width: 150 },
  { align: 'center', title: '支数', dataIndex: 'productBranch', key: 'productBranch', width: 150 },
  { align: 'center', title: '看台定额', width: 150, dataIndex: 'fixedMachinesNum', key: 'fixedMachinesNum' },
  { align: 'center', title: '锭数', dataIndex: 'ingots', key: 'ingots', width: 150 },
  { align: 'center', title: '定额产量', width: 150, dataIndex: 'weight', key: 'weight' },
  { align: 'center', title: '单价', width: 150, dataIndex: 'outputPrice', key: 'outputPrice' },
  {
    align: 'center',
    title: '品种系数',
    dataIndex: 'productTypeCoefficient',
    key: 'productTypeCoefficient',
    width: 150
  },
  { align: 'center', title: '单价系数', dataIndex: 'unitPriceCoefficient', key: 'unitPriceCoefficient', width: 150 },
  {
    align: 'center',
    title: '涡流纺换条单价',
    dataIndex: 'changeStripUnitPrice',
    key: 'changeStripUnitPrice',
    width: 150
  },
  { align: 'center', title: '是否托盘', dataIndex: 'isPlate', key: 'isPlate', width: 200 },
  { align: 'center', title: '系数调整', dataIndex: 'coefficientAdjust', key: 'coefficientAdjust', width: 200 },
  {
    title: '操作',
    dataIndex: 'action',
    align: 'center',
    scopedSlots: { customRender: 'action' },
    fixed: 'right'
  }
]
</script>
<style scoped>
.body {
  background: #fff;
  padding: 15px;
}
</style>
